﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Liju.Model;
using LiJu.Model.Model;

namespace LiJu.Db
{
    public class Bll
    {
        /// <summary>
        /// 查 COM端口设置列表
        /// </summary>
        /// <returns></returns>
        public static DataTable GetComPortList()
        {
            string strMySql = "select * from ComPort";
            DataTable dt = DalMySQL.ExecuteDataTable(strMySql);
            return dt;
        }

        /// <summary>
        /// 更新COM端口设置 0力臂 1电批 2套筒 3上料机
        /// </summary>
        /// <param name="PortType">0力臂 1电批 2套筒 3上料机</param>
        /// <param name="PortName">COM端口名称</param>
        /// <returns></returns>
        public static int UpdateComPort(int PortType, string PortName)
        {
            string strMySql = "update ComPort set PortName='" + PortName + "' where PortType=" + PortType;
            return DalMySQL.ExecuteNonQuery(strMySql);

            //执行不报错 但不成功 原因待查
            //string strMySql = "update ComPort set PortName='@PortName' where PortType=@PortType";
            //MySqlParameter[] parms = new MySqlParameter[]{
            //    new MySqlParameter("@PortName", PortName),
            //    new MySqlParameter("@PortType", PortType)
            //};
            //return DalMySQL.ExecuteNonQuery(strMySql, parms);
        }

        /// <summary>
        /// 查询所有套筒型号
        /// </summary>
        /// <returns></returns>
        public static List<SleeveModel> GetAllSleeveModels()
        {
            string strMySql = "select * from sleevemodel";
            DataTable dt = DalMySQL.ExecuteDataTable(strMySql);
            var sleevemodels = DbExtension.DataTableToList<SleeveModel>(dt);
            return sleevemodels;
        }

        /// <summary>
        /// 查询所有螺丝型号
        /// </summary>
        /// <returns></returns>
        public static List<ScrewModel> GetAllScrewModels()
        {
            string strMySql = "select * from screwmodel limit 2";
            DataTable dt = DalMySQL.ExecuteDataTable(strMySql);
            var screwmodels = DbExtension.DataTableToList<ScrewModel>(dt);
            return screwmodels;
        }

        /// <summary>
        /// 查询所有任务参数
        /// </summary>
        /// <returns></returns>
        public static List<ScrewDriverParamModel> GetAllParameters()
        {
            string strMySql = "select * from parameter";
            DataTable dt = DalMySQL.ExecuteDataTable(strMySql);
            var taskparams = DbExtension.DataTableToList<ScrewDriverParamModel>(dt);
            return taskparams;
        }

        /// <summary>
        /// 查询所有DDK参数
        /// </summary>
        /// <returns></returns>
        public static List<DDKScrewParam> GetAllDDKParameter()
        {
            //获取没有删除的产品
            string strMySql = $"select * from ddkparameter order by taskId";
            DataTable dt = DalMySQL.ExecuteDataTable(strMySql);
            var parameters = DbExtension.DataTableToList<DDKScrewParam>(dt);
            return parameters;
        }

        /// <summary>
        /// 查询指定任务 DDK参数
        /// </summary>
        /// <returns></returns>
        public static List<DDKScrewParam> GetDDKParameter(int TaskID)
        {
            //获取没有删除的产品
            string strMySql = $"select * from ddkparameter where TaskID='"+ TaskID + "' order by taskId";
            DataTable dt = DalMySQL.ExecuteDataTable(strMySql);
            var parameters = DbExtension.DataTableToList<DDKScrewParam>(dt);
            return parameters;
        }

        /// <summary>
        /// 获取语音文件列表
        /// </summary>
        /// <returns></returns>
        public static DataTable GetSoundFileList()
        {
            string strMySql = "select * from VoiceFile";
            DataTable dt = DalMySQL.ExecuteDataTable(strMySql);
            return dt;
        }

    }
}
